package com.anzia.set;

import java.util.Comparator;
import java.util.TreeSet;

/**
 *@ClassName TreeSet2_Demo
 *@Description
 *@Author Anzia.
 *@Date 2021/4/10 15:10
 *@Version 1.0
 **/
public class TreeSet2_Demo {
    public static void main(String[] args) {
        TreeSet<String> treeSet = new TreeSet<>(new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                int n1 = o1.length() - o2.length();
                int n2 = o1.compareTo(o2);
                return n1 == 0 ? n2 : n1;
            }
        });

        treeSet.add("helloworld");
        treeSet.add("zhand");
        treeSet.add("lisi");
        treeSet.add("beijing");
        treeSet.add("xian");
        treeSet.add("nanjing");

        System.out.println(treeSet);
    }
}
